package net.sxnic.ugr.user.action;

import net.sxnic.comm.CommConstant;
import net.sxnic.ugr.UgrActionSupport;
import net.sxnic.ugr.dept.Dept;
import net.sxnic.ugr.dept.DeptManager;
import net.sxnic.ugr.user.User;
import net.sxnic.ugr.user.UserManager;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 
 * Comments: 更新用户的所属部门
 * <p>
 * Author：孙宇飞
 * <p>
 * Create Date：2010-6-9
 * <p>
 * 
 * 
 */
@SuppressWarnings("serial")
public class UpdateUserDept extends UgrActionSupport {

	private static Logger logger = LoggerFactory
			.getLogger(UpdateUserDept.class);

	private String dept;

	@Autowired
	private UserManager userManager;

	@Autowired
	private DeptManager deptManager;

	public String execute() throws Exception {

		User user = userManager.get(id);

		String tempCodes = "";

//		if (StringUtils.isBlank(dept)) {
//			user.getDepts().clear();
//		} else {
//			String[] depts = StringUtils.split(dept, ",");
//
//			user.getDepts().clear();
//
//			Dept deptment = null;
//			for (String d : depts) {
//				//deptment = deptManager.findByCode(d,CommConstant.PROPERTY_MAP.get("zb.optYear"));
//
//				logger.debug("dept id :" + deptment.getId() + " , user id :"
//						+ user.getId());
//
//				user.getDepts().add(deptment);
//
//				tempCodes = tempCodes + deptment.getName() + ",";
//			}
//
//			user.setDeptCodes(StringUtils.removeEnd(tempCodes, ","));
//		}

		userManager.update(user);

		return SUCCESS;
	}

	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

}
